package com.hksj.Intelligentmanagement.controller;

import com.hksj.Intelligentmanagement.common.Result;
import com.hksj.Intelligentmanagement.dto.RegionDTO;
import com.hksj.Intelligentmanagement.service.RegionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(tags = "区域管理")
@RestController
@RequestMapping("/api/region")
public class RegionController {

    @Autowired
    private RegionService regionService;

    @ApiOperation(value = "区域新增")
    @PostMapping("/saveRegion")
    public Result saveRegion(@RequestBody RegionDTO regionDTO) {
        return regionService.saveRegion(regionDTO);
    }

    @ApiOperation(value = "区域删除")
    @GetMapping("/delRegion{id}")
    public Result delRegion(@PathVariable("id") String id) {
        return  regionService.delRegion(id);
    }

    @ApiOperation("区域修改")
    @PostMapping("/updateRegion")
    public Result updateRegion(@RequestBody @Validated(RegionDTO.Update.class) RegionDTO regionDTO) {
        return regionService.updateRegion(regionDTO);
    }

    @ApiOperation("根据id查询区域信息")
    @GetMapping("/queryRegionById/{id}")
    public Result queryRegionById(@PathVariable("id") String id) {
        return regionService.queryRegionById(id);
    }

    @ApiOperation(value = "查询所有区域列表")
    @PostMapping("selectAllRegion")
    public Result selectAllRegion(@RequestBody RegionDTO regionDTO) {
        return Result.ok(regionService.selectAllRegion(regionDTO));
    }
}
